#include <stdio.h>
#include <stdlib.h>
 
#define STDIN
#define MAX 1034
int ans[MAX];
 
int MyCompare(const void *e1, const void *e2)
{
	return *((int*) e1) - *((int*) e2);
}
// www.wutianqi.com
int main()
{
#ifdef 	STDIN
	freopen("bin/1833.in", "r", stdin);
#endif
	int nCases;
	int num, k, i, j;
	scanf("%d", &nCases);
	while(nCases--)
	{
		scanf("%d %d", &num, &k);
		for(i = 1; i <= num; ++i)
			scanf("%d", &ans[i]);
		ans[0] = 1000000;    //ans[0]是哨兵，确保ans[0]比其他都大
		for(i = 0; i < k; ++i)   //每次循环都找出下一个排列
		{
			for(j = num; j >= 1 && ans[j-1] > ans[j]; --j)
				;
			if(j >= 1)
			{
				int nMinLarge = ans[j];
				int nMinId = j;
 
				//下面找出从ans[j]及其后最小的比ans[j-1]大的元素，并记住其下标
				for(int kk = j; kk <= num; ++kk)
					if(nMinLarge > ans[kk] && ans[kk] > ans[j-1])
					{
						nMinLarge = ans[kk];
						nMinId = kk;
					}
				//交换位置
				ans[nMinId] = ans[j-1];
				ans[j-1] = nMinLarge;
				qsort(ans+j, num-j+1, sizeof(int), MyCompare);
			}
			else
				for(j = 1; j <= num; ++j)
					ans[j] = j;
		}
		for(j = 1; j <= num; ++j)
			printf("%d ", ans[j]);
		printf("\n");
 
	}
	return 0;
}
